import 'dart:async';

import 'package:flutter/services.dart';

class _AppUpdater {
  static const EventChannel _channel =
      const EventChannel('app_updater');
  // 进度订阅
  StreamSubscription downloadSubscription;
  // 开始下载
  void startDownload(String url,callback) {
    stopDownload();
    if (downloadSubscription == null) {
      downloadSubscription = _channel.receiveBroadcastStream(url).listen(callback);
    }
  }

  // 停止监听进度
  void stopDownload() {
    if (downloadSubscription != null) {
      downloadSubscription.cancel();
      downloadSubscription = null;
    }
  }
}
_AppUpdater appUpdater = _AppUpdater();

